//
//  TJWelcomeViewController.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/19.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJWelcomeViewController.h"
#import "TJAccountViewModle.h"
#import "Masonry.h"
#import "TJMainViewController.h"
@interface TJWelcomeViewController ()
@property(nonatomic,weak)UIImageView *iconView;
@end

@implementation TJWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建界面.
    [self setupUI];
    
}
-(void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];
    [self addanimation];
}

// 头像和label的动画
- (void)addanimation{
    
    [self.iconView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-([UIScreen mainScreen].bounds.size.height - 150));
    }];
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:6 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        // 动画完成后跳转到主界面.
        [UIApplication sharedApplication].keyWindow.rootViewController = [[TJMainViewController alloc] init];
    }];
}

// 设置UI
- (void)setupUI {
    
    // 1,添加子控件.
    // 1.1背景.
    UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_background"]];
    [self.view addSubview:bgView];
    
    // 1.2头像.
    UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    self.iconView = iconView;
    // 设置圆角.
    iconView.layer.cornerRadius = 42.5;
    iconView.layer.masksToBounds = YES;
    [self.view addSubview:iconView];
    
    // 1.3namelabel
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"欢迎归来";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:nameLabel];
    
    // 2,布局子控件.
    // 背景.
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    // 头像.
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-160);
    }];
    
    // label.
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(iconView.mas_bottom).offset(16);
    }];
    
    
    
    
}
@end
